<?php
 
/*
 * Following code will update a bet.
 * Only the acceptorID is ever updated.
 */
 
// array for JSON response
$response = array();
 
// check for required fields
if (isset($_POST['betID']) && isset($_POST['bettorID']) && isset($_POST['acceptorID'] && isset($_POST['value'])) {
 
    $betID = $_POST['betID'];
	$bettorID = $_POST['bettorID'];
	$acceptorID = $_POST['acceptorID'];
	$value = $_POST['value'];
 
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
 
    // connecting to db
    $db = new DB_CONNECT();
 
    // mysql update row with matched pid
    $result = mysql_query("UPDATE mmg_bets SET acceptorID = $acceptorID WHERE betID = $betID AND acceptorID = NULL");
 
    // check if row inserted or not
    if ($result) {
        // successfully updated
        $response["success"] = 1;
        $response["message"] = "Product successfully updated.";
 
        // echoing JSON response
        echo json_encode($response);
    } else {
		// bet was claimed by someone else
		$response["success"] = 0;
		$response["message"] = "Bet has already been claimed!";
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
 
    // echoing JSON response
    echo json_encode($response);
}
?>